<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Alejandro Casas
 * Date: 1/28/13
 * Time: 12:15 PM
 * To change this template use File | Settings | File Templates.
 */

require_once 'DataLoader.php';

include_once('httpful-0.2.0.phar');



class SearchWS
{
    private $client;
    public function __construct() {
        $this->client = $_SESSION['base_server_url'];
    }

    public function testGet($param)
    {
        $uri=$this->client."get/".$param;
        $r = \Httpful\Request::get($uri)->sendIt();
        return $r;


    }

    public function testPOST($param)
    {



        $uri=$this->client."post";
        $r = \Httpful\Request::post($uri)
        ->body($param)->send();
        return $r;
    }

    public function testJSON($mailOwner,
		$nameOwner,
		$title,
		$address,
		$description,
		$ending_date,
		$starting_date,
		$lat,
		$lng,
		$miniPicture,
		$picture,
		$openings,
		$privacy,
		$sports,
		$city,
		$country)
    {
        $uri=$this->client."json";
        $parameters='{
    "mailOwner":'.$mailOwner.',
	"nameOwner":'.$nameOwner.',
	"title":'.$title.',
	"address":'.$address.',
	 "description":'.$description.',
	"ending_date":'.$ending_date.',
	 "starting_date":'.$starting_date.',
	"lat":'.$lat.',
	"lng":'.$lng.',
	 "miniPicture":'.$miniPicture.',
	 "picture":'.$picture.',
	"openings":'.$openings.',
	"privacy":'.$privacy.',
	"city":'.$city.',
	"country":'.$country.'
        }';
        $r = \Httpful\Request::post($uri)
            ->sendsJson()
            ->body($parameters)
            ->send();
        return $r;
    }

public function Feedback($mail,
$subject,$comment)
{
$uri=$this->client."json";
$parameters='{
    "mail":'.$mail.',
	"subject":'.$subject.',
	"comment":'.$comment.',
        }';
$r = \Httpful\Request::post($uri)
->sendsJson()
->body($parameters)
->send();
return $r;
}
public function GetUsersType($mail)
{
    $uri=$this->client."json";
    $parameters='{
    "mail":'.$mail.',
        }';
    $r = \Httpful\Request::post($uri)
        ->sendsJson()
        ->body($parameters)
        ->send();
    return $r;
}
public function  GetEventInfo($id,$viewer)
{
    $uri=$this->client."json";
    $parameters='{
    "id":'.$id.',
    "viewer"'.$viewer.'}';
    $r = \Httpful\Request::post($uri)
        ->sendsJson()
        ->body($parameters)
        ->send();
    return $r;
}
public function  GetEventparticipationRequest($id)
{
    $uri=$this->client."json";
    $parameters='{
    "id":'.$id.'}';
    $r = \Httpful\Request::post($uri)
        ->sendsJson()
        ->body($parameters)
        ->send();
    return $r;
}
public function AcceptEventParticpationRequest($eventId,$mail,$nameFrom)
{
    $uri=$this->client."json";
    $parameters='{
    "eventId":'.$eventId.',
    "mail":'.$mail.',
    "nameFrom"'.$nameFrom.'}';
    $r = \Httpful\Request::post($uri)
        ->sendsJson()
        ->body($parameters)
        ->send();
    return $r;
}
public function RejectEventParticipationRequest($eventId,$mail,$nameFrom)
{
    $uri=$this->client."json";
    $parameters='{
    "eventId":'.$eventId.',
    "mail":'.$mail.',
    "nameFrom"'.$nameFrom.'}';
    $r = \Httpful\Request::post($uri)
        ->sendsJson()
        ->body($parameters)
        ->send();
    return $r;
}
public function GetEventRegisteredParticipants($eventId,$viewer)
{
    $uri=$this->client."json";
    $parameters='{
    "eventId":'.$eventId.',
    "viewer":'.$viewer.'}';
    $r = \Httpful\Request::post($uri)
        ->sendsJson()
        ->body($parameters)
        ->send();
    return $r;
}
public function  GetUserConversations($mail)
{
    $uri=$this->client."json";
    $parameters='{
    "mail":'.$mail.'}';
    $r = \Httpful\Request::post($uri)
        ->sendsJson()
        ->body($parameters)
        ->send();
    return $r;
}
public function GetConversationMessages($mailUser)
{
    $uri=$this->client."json";
    $parameters='{
    "mailUser":'.$mailUser.'}';
    $r = \Httpful\Request::post($uri)
        ->sendsJson()
        ->body($parameters)
        ->send();
    return $r;
}
public function GetUserBasicInfo($mail,$viewer)
{
    $uri=$this->client."GetUserBasicInfo";
    $parameters='{
    "mail":"'.$mail.'",
    "viewer":"'.$viewer.'"}';
    $r = \Httpful\Request::post($uri)
        ->sendsJson()
        ->body($parameters)
        ->send();
    return $r;
}
public function SendMessage($mailFrom,$mailTo,$title,$message,$nameFrom,$miniPictureFrom)
{
    $uri=$this->client."json";
    $parameters='{
    "mailFrom":'.$mailFrom.',
    "mailTo":'.$mailTo.',
    "title":'.$title.',
    "message":'.$message.',
    "nameFrom":'.$nameFrom.',
    "miniPictureFrom":'.$miniPictureFrom.'}';
    $r = \Httpful\Request::post($uri)
        ->sendsJson()
        ->body($parameters)
        ->send();
    return $r;
}
public function  SetStatus($mail,$status)
{
    $uri=$this->client."json";
    $parameters='{
    "mail":'.$mail.',
    "status":'.$status.'}';
    $r = \Httpful\Request::post($uri)
        ->sendsJson()
        ->body($parameters)
        ->send();
    return $r;
}
public function  GetUserReviews($mail,$viewer)
{
    $uri=$this->client."json";
    $parameters='{
    "mail":'.$mail.',
    "viewer":'.$viewer.'}';
    $r = \Httpful\Request::post($uri)
        ->sendsJson()
        ->body($parameters)
        ->send();
    return $r;
}
public function  ReportUser($mailReporter, $mailReported,$message)
{
    $uri=$this->client."json";
    $parameters='{
    "mailReporter":'.$mailReporter.',
    "mailReported":'.$mailReported.',
    "message":'.$message.'}';
    $r = \Httpful\Request::post($uri)
        ->sendsJson()
        ->body($parameters)
        ->send();
    return $r;
}
public function Follow($mailFollower,$mailFollowed)
{
    $uri=$this->client."json";
    $parameters='{
    "mailFollower":'.$mailFollower.',
    "mailFollowed":'.$mailFollowed.'}';
    $r = \Httpful\Request::post($uri)
        ->sendsJson()
        ->body($parameters)
        ->send();
    return $r;
}
public function  Unfollow($mailFollower,$mailFollowed)
{
    $uri=$this->client."json";
    $parameters='{
    "mailFollower":'.$mailFollower.',
    "mailFollowed":'.$mailFollowed.'}';
    $r = \Httpful\Request::post($uri)
        ->sendsJson()
        ->body($parameters)
        ->send();
    return $r;
}
public function  WriteReview($mailFrom,$mailTo,$sport,$calification,$title,$message,$nameFrom)
{
    $uri=$this->client."json";
    $parameters='{
    "mailFrom":'.$mailFrom.',
    "mailTo":'.$mailTo.',
    "sport":'.$sport.',
    "calification":'.$calification.',
    "title":'.$title.',
    "message":'.$message.',
    "nameFrom":'.$nameFrom.'}';
    $r = \Httpful\Request::post($uri)
        ->sendsJson()
        ->body($parameters)
        ->send();
    return $r;
}
public function GetFollowers($mail,$viewer)
{
    $uri=$this->client."json";
    $parameters='{
    "mail":'.$mail.',
    "viewer":'.$viewer.'}';
    $r = \Httpful\Request::post($uri)
        ->sendsJson()
        ->body($parameters)
        ->send();
    return $r;
}
public function  ReportEvent($eventId,$mailReporter,$message)
{
    $uri=$this->client."json";
    $parameters='{
    "eventId":'.$eventId.',
    "mailReporter":'.$mailReporter.',
    "message":'.$message.'}';
    $r = \Httpful\Request::post($uri)
        ->sendsJson()
        ->body($parameters)
        ->send();
    return $r;
}
public function  VerifyUser($mail,$password)
{
    $uri=$this->client."json";
    $parameters='{
    "mail":'.$mail.',
    "password":'.$password.'}';
    $r = \Httpful\Request::post($uri)
        ->sendsJson()
        ->body($parameters)
        ->send();
    return $r;
}
public function  SearchPlayers($mail,$sport,$city,$country,$privacy,$dateFrom,$dateTo)
{
    $uri=$this->client."SearchPlayers";
    $parameters='{
    "mail":"'.$mail.'",
    "sport":"'.$sport.'",
    "city":"'.$city.'",
    "country":"'.$country.'",
    "privacy":"'.$privacy.'",
    "dateFrom":"'.$dateFrom.'",
    "dateTo":"'.$dateTo.'"}';
    $r = \Httpful\Request::post($uri)
        ->sendsJson()
        ->body($parameters)
        ->send();
    return $r;
}
public function  SearchBusiness($mail,$city,$country,$privacy,$sport)
{
    $uri=$this->client."json";
    $parameters='{
    "mail":'.$mail.',
    "sport":'.$sport.',
    "city":'.$city.',
    "country":'.$country.',
    "privacy":'.$privacy.'}';
    $r = \Httpful\Request::post($uri)
        ->sendsJson()
        ->body($parameters)
        ->send();
    return $r;
}
public function  SearchCoaches($mail,$sport,$city,$country,$privacy)
{
    $uri=$this->client."json";
    $parameters='{
    "mail":'.$mail.',
    "sport":'.$sport.',
    "city":'.$city.',
    "country":'.$country.',
    "privacy":'.$privacy.'}';
    $r = \Httpful\Request::post($uri)
        ->sendsJson()
        ->body($parameters)
        ->send();
    return $r;
}
public function  SearchEvents($mail,$sport,$city,$country,$privacy)
{
    $uri=$this->client."json";
    $parameters='{
    "mail":'.$mail.',
    "sport":'.$sport.',
    "city":'.$city.',
    "country":'.$country.',
    "privacy":'.$privacy.'}';
    $r = \Httpful\Request::post($uri)
        ->sendsJson()
        ->body($parameters)
        ->send();
    return $r;
}
public function  SearchUsers($string,$viewer)
{
    $uri=$this->client."json";
    $parameters='{
    "string":'.$string.',
    "viewer":'.$viewer.'}';
    $r = \Httpful\Request::post($uri)
        ->sendsJson()
        ->body($parameters)
        ->send();
    return $r;
}
public function  GeneralSearch($string,$viewer)
{
    $uri=$this->client."GeneralSearch";
    $parameters='{
    "string":"'.$string.'",
    "viewer":"'.$viewer.'"}';
    $r = \Httpful\Request::post($uri)
        ->sendsJson()
        ->body($parameters)
        ->send();

    return $r;
}
public function GetUserFriends($mail,$viewer)
{
    $uri=$this->client."json";
    $parameters='{
    "mail":'.$mail.',
    "viewer":'.$viewer.'}';
    $r = \Httpful\Request::post($uri)
        ->sendsJson()
        ->body($parameters)
        ->send();
    return $r;
}
    /*
	@POST
	@Path(value="GetPlayerInfo")
	@Produces(MediaType.APPLICATION_JSON)
	public Full_User GetPlayerInfo(final JaxCommonClases.)
	{
        return (new CluvieMain()).getPlayerInfo(mail,viewer);
    }
	@POST
	@Path(value="GetCoachInfo")
	@Produces(MediaType.APPLICATION_JSON)
	public Full_User GetCoachInfo(final JaxCommonClases.)
	{
        return (new CluvieMain()).getCoachInfo(mail,viewer);
    }
	@POST
	@Path(value="GetBusinessInfo")
	@Produces(MediaType.APPLICATION_JSON)
	public Full_User GetBusinessInfo(final JaxCommonClases.)
	{
        return (new CluvieMain()).getBusinessInfo(mail,viewer);
    }
	
	
	
	@POST
	@Path(value="CreateEvent")
	@Produces(MediaType.APPLICATION_JSON)
	public Event_Info CreateEvent(final JaxCommonClases.JaxEventInfo event)
	{

        return (new CluvieMain()).createEvent(event.mailOwner,event.nameOwner,event.title,event.address,
            event.description,event.ending_date,event.starting_date,event.lat,event.lng,
            event.miniPicture,event.picture,event.openings,event.privacy,event.sports,
            event.city,event.country);
    }
	
	@POST
	@Path(value="GetUserEvents")
	@Produces(MediaType.APPLICATION_JSON)
	public List<JSON_event> GetUserEvents($mail") 
			,$viewer") 
			String viewer)
	{
        return (new CluvieMain()).getUserEvents(mail,viewer);
    }
	@POST
	@Path(value="GetNotifications")
	@Produces(MediaType.APPLICATION_JSON)
	public List<JSON_notification> GetNotifications($mail") 
			)
	{
        return (new CluvieMain()).getNotifications(mail);
    }
	
	@POST
	@Path(value="DeleteConversation")
	@Produces(MediaType.APPLICATION_JSON)
	public boolean DeleteConversation($mailUser") 
			
			With)
	{
        return (new CluvieMain()).deleteConversation(mailUser,mailWith);
    }
	
	@POST
	@Path(value="DeleteMessage")
	@Produces(MediaType.APPLICATION_JSON)
	public boolean DeleteMessage($mailUser") 
			User,$messageId") 
			long messageId,$mailWriter") 
			Writer)
	{
        return (new CluvieMain()).deleteMessage(mailUser,messageId,mailWriter);

    }
	
	@POST
	@Path(value="GetSports")
	@Produces(MediaType.APPLICATION_JSON)
	public List<String> GetSports()
    {
    /*
    CluvieMain cm=new CluvieMain();
    return cm.getSports();
    *
		List<String> l=new ArrayList<String>();
		for (int i = 0; i < 5; i++) {
    l.add("s"+i);
}
		return l;
		
	}
	
	@POST
	@Path(value="GetCities")
	@Produces(MediaType.APPLICATION_JSON)
	public List<String> GetCities($country") 
			String country)
	{
        return (new CluvieMain()).getCities(country);

    }
	
	@POST
	@Path(value="DeleteReview")
	@Produces(MediaType.APPLICATION_JSON)
	public boolean DeleteReview($id") 
			long id,$mailWriter") 
			Writer,$mailTo") 
			To)
	{
        return (new CluvieMain()).deleteReview(id,mailWriter,mailTo);

    }
	@POST
	@Path(value="DeleteEvent")
	@Produces(MediaType.APPLICATION_JSON)
	public boolean DeleteEvent($id") 
			long id,$mailSession") 
			Session)
	{
        return (new CluvieMain()).deleteEvent(id,mailSession);

    }
	@POST
	@Path(value="DeleteDiscount")
	@Produces(MediaType.APPLICATION_JSON)
	public boolean DeleteDiscount($id") 
			long id,$mailSession") 
			Session)
	{
        return (new CluvieMain()).deleteDiscount(id,mailSession);

    }
	
	@POST
	@Path(value="WriteCommentToEvent")
	@Produces(MediaType.APPLICATION_JSON)
	public boolean WriteCommentToEvent($eventId") 
			,$mail") 
			,$message") 
			String message)
	{
        return (new CluvieMain()).writeCommentToEvent(eventId,mail,message);

    }
	
	@POST
	@Path(value="SendEventSuggestion")
	@Produces(MediaType.APPLICATION_JSON)
	public boolean SendEventSuggestion($mailSender") 
			Sender,$mailTo") 
			To,$eventId") 
			)
	{
        return new CluvieMain().sendEventSuggestion(mailSender,mailTo,eventId);
    }
	*/


}
